import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:test01/okhttp_test/page/indexlogin/setup_page.dart';
import 'package:test01/okhttp_test/pojo/saveBasicFitnessInfo_pojo.dart';
import 'package:test01/okhttp_test/util/request_http.dart';

/*
*
*
* 登录界面--输入体重
*
* */
///输入你的体重
class IndexWeightPage extends StatefulWidget {
  const IndexWeightPage({Key key}) : super(key: key);

  @override
  _IndexWeightPageState createState() => _IndexWeightPageState();
}

class _IndexWeightPageState extends State<IndexWeightPage> {
  int weight_value;
  int height_value;

  bool isHeightWeight=false;

  SaveBasicFitnessInfo saveBasicFitnessInfos=SaveBasicFitnessInfo();

  ///判断输入数据是否正确

   void isWeight() {
    if(weight_value!=null&&height_value!=null){
      print("----------------------调用实体类----------------------");
      isHeightWeight=true;
      saveBasicFitnessInfos.heights=height_value;
      saveBasicFitnessInfos.weight=weight_value;

      print("获取的数据--------------------------${saveBasicFitnessInfos.toString()}");
    }else{
      isHeightWeight=false;
    }
    setState(() {
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar:  AppBar(
        leading: GestureDetector(
          onTap: (){
            Navigator.pop(context);
          },
          child: Icon(
            Icons.arrow_back_ios,
            size: 28,
            color: Colors.black,
          ),
        ),
        backgroundColor: Colors.white,
        elevation: 0,
        automaticallyImplyLeading: true,
      ),
      body: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              margin: EdgeInsets.only(top: 42.5, left: 41),
              child: Text(
                "你的身高体重是",
                style:
                TextStyle(fontSize: 23, color: Color.fromRGBO(17, 17, 17, 1)),
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 12, left: 41),
              child: Text(
                "我们将以此为你推荐训练计划，让你一试身手。",
                style:
                TextStyle(fontSize: 14, color: Color.fromRGBO(51, 51, 51, 1)),
              ),
            ),
            Container(
              alignment: Alignment.center,
              margin: EdgeInsets.only(
                top: 42,
              ),
              child: Text(
                "身高",
                style:
                TextStyle(fontSize: 18, color: Color.fromRGBO(17, 17, 17, 1)),
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  margin: EdgeInsets.only(left: 23),
                  width: MediaQuery.of(context).size.width - 235,
                  child: TextField(
                    keyboardType: TextInputType.number,
                    textAlign: TextAlign.center,
                    autofocus: false,
                    cursorColor: Color.fromRGBO(17, 17, 17, 1),
                    decoration: InputDecoration(
                      counterText: "",
                      hintMaxLines: 1,
                      /// 不是焦点的时候颜色
                      enabledBorder: UnderlineInputBorder(
                        borderSide:
                        BorderSide(color: Color.fromRGBO(243, 243, 243, 1)),
                      ),

                      /// 焦点集中的时候颜色
                      focusedBorder: new UnderlineInputBorder(
                        borderSide:
                        BorderSide(color: Color.fromRGBO(243, 243, 243, 1)),
                      ),
                    ),
                    maxLength: 3,
                    onChanged: (value){
                      height_value=int.parse(value);
                      isWeight();
                      setState(() {});
                    },
                  ),
                ),
                Container(
                    alignment: Alignment.bottomLeft,
                    margin: EdgeInsets.only(left: 4),
                    child: Text(
                      "CM",
                      style: TextStyle(
                          fontSize: 16, color: Color.fromRGBO(204, 204, 204, 1)),
                    ))
              ],
            ),
            Container(
              alignment: Alignment.center,
              margin: EdgeInsets.only(
                top: 42,
              ),
              child: Text(
                "体重",
                style:
                TextStyle(fontSize: 18, color: Color.fromRGBO(17, 17, 17, 1)),
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  margin: EdgeInsets.only(left: 23),
                  width: MediaQuery.of(context).size.width - 235,
                  child: TextField(
                    keyboardType: TextInputType.number,
                    maxLength: 3,
                    textAlign: TextAlign.center,
                    autofocus: false,
                    cursorColor: Color.fromRGBO(17, 17, 17, 1),
                    decoration: InputDecoration(
                      hintMaxLines: 1,
                      counterText: "",
                      /// 不是焦点的时候颜色
                      enabledBorder: UnderlineInputBorder(
                        borderSide:
                        BorderSide(color: Color.fromRGBO(243, 243, 243, 1)),
                      ),

                      /// 焦点集中的时候颜色
                      focusedBorder: new UnderlineInputBorder(
                        borderSide:
                        BorderSide(color: Color.fromRGBO(243, 243, 243, 1)),
                      ),
                    ),
                    onChanged: (value){
                      weight_value=int.parse(value);
                      isWeight();
                      setState(() {});
                    },
                  ),
                ),
                Container(
                    alignment: Alignment.bottomLeft,
                    margin: EdgeInsets.only(left: 4),
                    child: Text(
                      "KG",
                      style: TextStyle(
                          fontSize: 16, color: Color.fromRGBO(204, 204, 204, 1)),
                    ))
              ],
            ),
            GestureDetector(
              onTap: () async{
                if(isHeightWeight) {
                  bool xx=await saveBasicFitnessInfo(saveBasicFitnessInfos,"/appuser/web/user/saveBasicFitnessInfo");
                 if(xx){
                   Navigator.push(context, MaterialPageRoute(builder: (context) {
                     return IndexShapePage();
                   }));
                 }
                }

              },
              child:isHeightWeight?
              Container(
                alignment: Alignment.center,
                height: 41,
                decoration: BoxDecoration(
                  color: Color.fromRGBO(17, 17, 17, 1),
                  borderRadius: BorderRadius.all(Radius.circular(3.0)),
                ),
                width: MediaQuery.of(context).size.width - 82,
                margin: EdgeInsets.only(left: 41, top: 62),
                child: Text(
                  "下一步",
                  style: TextStyle(
                      fontSize: 16, color: Color.fromRGBO(255, 255, 255, 1)),
                ),
              ):
              Container(
                alignment: Alignment.center,
                height: 41,
                decoration: BoxDecoration(
                  color: Color.fromRGBO(17, 17, 17, 0.06),
                  borderRadius: BorderRadius.all(Radius.circular(3.0)),
                ),
                width: MediaQuery.of(context).size.width - 82,
                margin: EdgeInsets.only(left: 41, top: 62),
                child: Text(
                  "下一步",
                  style: TextStyle(
                      fontSize: 16, color: Color.fromRGBO(153, 153, 153, 1)),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}


